package com.yw.swagger.service.serviceImpl;

import com.yw.swagger.mapper.SysBpsGpmemlnkMapper;
import com.yw.swagger.mapper.SysBpsUsersMapper;
import com.yw.swagger.model.SysBpsUsers;
import com.yw.swagger.service.SysBpsUsersService;
import com.yw.swagger.tool.AjaxResult;
import com.yw.swagger.tool.Utils.Md5Utils;
import com.yw.swagger.tool.Utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by 14267 on 2019/10/24
 */
@Service
public class SysBpsUsersServiceImpl implements SysBpsUsersService {

    @Autowired
    private SysBpsUsersMapper sysBpsUsersMapper;

    @Autowired
    private SysBpsGpmemlnkMapper sysBpsGpmemlnkMapper;
    @Override
    public AjaxResult userLogin(String account, String pwd, HttpServletRequest request) {
        String password = Md5Utils.hash(pwd);
        SysBpsUsers user = sysBpsUsersMapper.selectUsersByAccount(account);
        if(StringUtils.isNull(user)){
            return AjaxResult.error("用户名不存在");
        }
        if(!user.getUSER_PWD().equals(password)){
            return AjaxResult.error("密码错误");
        }
        HttpSession session = request.getSession();
        session.setAttribute("name", account);
        session.setMaxInactiveInterval(-1);
        AjaxResult aj = new AjaxResult(AjaxResult.Type.SUCCESS,null);
        aj.put("data",user);
        aj.put("ground",sysBpsGpmemlnkMapper.selectGroundByAc(user.getUSER_Account()));
        return aj;
    }


    //查询用户详情
    @Override
    public SysBpsUsers selectSysBpsUsers(String userAccout) {
        return sysBpsUsersMapper.selectSysBpsUsers(userAccout);
    }
    //用户名查询用户账号
    @Override
    public List<SysBpsUsers> selectUserAccount(String[] userName) {
        return sysBpsUsersMapper.selectUserAccount(userName);
    }
}
